package creational_pattern.abstract_factory_pattern;

public class AbstractFactoryPattern {
    public static void main(String[] args) {
        Factory factory1 = new AlibabaFctory();
        Factory factory2 = new BaiduFctory();
        ProductA productA = factory1.createProductA();
        productA.display();
        System.out.println("----------");
        ProductA preparing_workA = factory1.createProductA("preparing_workA");
        preparing_workA.display();
        System.out.println("----------");
        ProductB preparing_workB = factory1.createProductB("preparing_workB");
        preparing_workB.display();
        System.out.println("----------");
        ProductB productB = factory1.createProductB("productB");
        productB.display();
        System.out.println("----------");
        ProductA productA1 = factory2.createProductA();
        productA1.display();
        System.out.println("----------");
        ProductB productB1 = factory2.createProductB();
        productB1.display();

    }
}

abstract class ProductA{
    abstract void display();
}
class AlibabaProductA1 extends  ProductA{

    @Override
    void display() {
        System.out.println("AlibabaProductA1");
    }
}
class BaiduProductA2 extends ProductA{

    @Override
    void display() {
        System.out.println("BaiduProductA2");
    }
}
abstract class ProductB{
    abstract void display();
}
class AlibabaProductB1 extends  ProductB{
    @Override
    void display() {
        System.out.println("AlibabaProductB1");
    }
}
class BaiduProductB2 extends ProductB{
    @Override
    void display() {
        System.out.println("BaiduProductB2");
    }
}
//声明了一组用于创建一族的对象的方法
interface Factory{
    ProductA createProductA();
    ProductA createProductA(String args);
    ProductB createProductB();
    ProductB createProductB(String args);
}
//创建alibaba产品族的对象
class AlibabaFctory implements Factory {
    @Override
    public ProductA createProductA() {
        return new AlibabaProductA1();
    }

    @Override
    public ProductA createProductA(String args) {
        System.out.println(args);
        return new AlibabaProductA1();
    }

    @Override
    public ProductB createProductB() {
        return new AlibabaProductB1();
    }

    @Override
    public ProductB createProductB(String args) {
        System.out.println(args);
        return new AlibabaProductB1();
    }
}
//创建baidu产品族的对象
class BaiduFctory implements Factory {
    @Override
    public ProductA createProductA() {
        return new BaiduProductA2();
    }

    @Override
    public ProductA createProductA(String args) {
        System.out.println(args);
        return new BaiduProductA2();
    }

    @Override
    public ProductB createProductB() {
        return new BaiduProductB2();
    }

    @Override
    public ProductB createProductB(String args) {
        System.out.println(args);
        return new BaiduProductB2();
    }
}
